package me.leiusual.sharing.ui.shop

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.fragment.findNavController
import dagger.android.support.DaggerFragment
import kotlinx.android.synthetic.main.fragment_shop_home.*
import me.leiusual.sharing.R
import javax.inject.Inject

/**
 * author: leiusual
 * create on: 2019-07-27
 * description: 我的店铺
 */
class ShopHomeFragment : DaggerFragment(), View.OnClickListener {

  @Inject
  lateinit var factory: ViewModelProvider.Factory

  private val viewModel: ShopHomeViewModel by viewModels { factory }

  override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
    return inflater.inflate(R.layout.fragment_shop_home, container, false)
  }

  override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)

    toolbar.setNavigationOnClickListener {
      findNavController().popBackStack()
    }

    text_view_order_all.setOnClickListener(this)
    text_view_bank.setOnClickListener(this)
    text_view_business.setOnClickListener(this)
    text_view_withdraw.setOnClickListener(this)
    text_view_user_account.setOnClickListener(this)
  }

  override fun onClick(v: View?) {
    when (v?.id) {
      R.id.text_view_order_all -> {
        val storeId = viewModel.store.currentStoreId
        val navDirections = ShopHomeFragmentDirections.actionShopHomeFragmentToOrderHomeFragment(3, storeId)
        findNavController().navigate(navDirections)
      }
      R.id.text_view_bank -> {
        findNavController().navigate(R.id.action_shopHomeFragment_to_shopBankFragment)
      }
      R.id.text_view_business -> {
        findNavController().navigate(R.id.action_shopHomeFragment_to_shopBusinessFragment)
      }
      R.id.text_view_withdraw -> {
        findNavController().navigate(R.id.action_shopHomeFragment_to_shopWithdrawFragment)
      }
      R.id.text_view_user_account -> {
        val navDirections = ShopHomeFragmentDirections.actionShopHomeFragmentToUserAccountFragment("store")
        findNavController().navigate(navDirections)
      }
    }
  }
}